package com.trc202.MemoryManagers;
//Term Project Ted Chandler and Daniel Moore
import java.util.ArrayList;
import java.util.Iterator;

import com.trc202.CS350.Job;
import com.trc202.CS350.MemorySegment;

public class FCFSFirstFit extends MemoryManager{
	
	public FCFSFirstFit(Job[] jobs, MemorySegment[] memory) {
		super(jobs, memory);
	}
	
	@Override
	public void manageMemory() {
		super.manageMemory();
		ArrayList<Job> avalableJobs = getAvalableJobs();
		for(Job j : avalableJobs){
			Iterator<MemorySegment> freeRam = getFreeRam().iterator();
			while(freeRam.hasNext()){
				MemorySegment mem = freeRam.next();
				if(j.getRequiredRam() <= mem.getSize()){
					j.setAssignedSegmentNum(mem.getSegmentNum());
					j.setStatus(Job.Status.READY);
					mem.setMBUsed(j.getRequiredRam());
					break;
				}
			}
		}
	}
}
